<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="付款单号" prop="payOrderNo">
        <el-input
          v-model="queryParams.payOrderNo"
          placeholder="请输入付款单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="业主姓名" prop="ownerName">
        <el-input
          v-model="queryParams.ownerName"
          placeholder="请输入业主姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="付款状态" prop="payState">
<!--        ,1、未付款；2、已付款3、已中止4、 4：已冻结-->
        <el-select v-model="queryParams.payState" clearable placeholder="请选择">
          <el-option
            v-for="item in payStates"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="账单类型" prop="billType">
        <el-select v-model="queryParams.billType" clearable placeholder="请选择">
          <el-option
            v-for="item in billTypes"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="收房合同编号" prop="contractNo">
        <el-input
          v-model="queryParams.contractNo"
          placeholder="请输入合同编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="实际付款日期" prop="paidTime">
        <el-date-picker clearable
                        v-model="queryParams.startDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择实际付款日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="---" prop="paidTime">
        <el-date-picker clearable
                        v-model="queryParams.endDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="请选择实际付款日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
<!--导出-->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['property:plan:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-tabs type="border-card"  @tab-click="tabs">
      <el-tab-pane label="收房付款单">
        <el-table v-loading="loading" :data="planList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
          <el-table-column label="id" align="center" prop="paymentId" />
        <el-table-column label="收房合同编号" align="center" prop="sfContractNo" />
        <el-table-column label="房产信息" align="center" prop="houseName" />
        <el-table-column label="业主姓名" align="center" prop="ownerName" />
        <el-table-column label="支付金额" align="center" prop="paymentAmount" />
        <el-table-column label="账期" align="center" prop="payNumber" >
          <template slot-scope="scope">
            <span>第{{scope.row.payNumber}}期</span>
          </template>
        </el-table-column>
        <el-table-column label="付款状态"  align="center" prop="payState" >
          <!--        ,1、未付款；2、已付款 3、已中止4、 4：已冻结-->
          <template slot-scope="scope">
            <span v-if="scope.row.payState==1">未付款</span>
            <span v-if="scope.row.payState==2">已付款</span>
            <span v-if="scope.row.payState==3">已中止</span>
            <span v-if="scope.row.payState==4">已冻结</span>
          </template>
        </el-table-column>
        <el-table-column label="账单类型" align="center" prop="billType" >
<!--          1：收房贷变更2：退租变更    3：普通账单(正常收房租务计划) 4：续约结算产生的"-->
          <template slot-scope="scope">
            <span v-if="scope.row.billType==1">收房贷变更</span>
            <span v-if="scope.row.billType==2">退租变更</span>
            <span v-if="scope.row.billType==3">普通账单</span>
            <span v-if="scope.row.billType==4">续约结算</span>
          </template>
        </el-table-column>
        <el-table-column label="预定付款日期" align="center" prop="payableDate" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.payableDate, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="实际付款日期" align="center" prop="paidTime" width="180">
          <template slot-scope="scope">
            <span>{{ parseTime(scope.row.paidTime, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column label="支付方式" align="center" prop="payMethod" >
        <!--      1:快捷同，2：支付宝，3：微信，4：现金，5：银行卡转账，6：POS机刷卡，99：其它-->
          <template slot-scope="scope">
            <span v-if="scope.row.payMethod==1">快捷同</span>
            <span v-if="scope.row.payMethod==2">支付宝</span>
            <span v-if="scope.row.payMethod==3">微信</span>
            <span v-if="scope.row.payMethod==4">现金</span>
            <span v-if="scope.row.payMethod==5">银行卡转账</span>
            <span v-if="scope.row.payMethod==6">POS机刷卡</span>
            <span v-if="scope.row.payMethod==99">其它</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="text"
              icon="el-icon-edit"
              v-if="scope.row.payMethod==undefined"
              @click="handleUpdate(scope.row)"
              v-hasPermi="['property:plan:edit']"
            >付款</el-button>
          </template>
        </el-table-column>
      </el-table>
      </el-tab-pane>
      <el-tab-pane label="租务付款单">
        <el-table v-loading="loading" :data="planList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column label="收房合同编号" align="center" prop="sfContractNo" />
          <el-table-column label="房产信息" align="center" prop="houseName" />
          <el-table-column label="业主姓名" align="center" prop="ownerName" />
          <el-table-column label="支付金额" align="center" prop="paymentAmount" />
          <el-table-column label="账期" align="center" prop="payNumber" >
            <template slot-scope="scope">
              <span>第{{scope.row.payNumber}}期</span>
            </template>
          </el-table-column>
          <el-table-column label="付款状态" align="center" prop="payState" >
            <!--        ,1、未付款；2、已付款 3、已中止4、 4：已冻结-->
            <template slot-scope="scope">
              <span v-if="scope.row.payState==1">未付款</span>
              <span v-if="scope.row.payState==2">已付款</span>
              <span v-if="scope.row.payState==3">已中止</span>
              <span v-if="scope.row.payState==4">已冻结</span>
            </template>
          </el-table-column>
          <el-table-column label="账单类型" align="center" prop="billType" >
            <!--          1：收房贷变更2：退租变更    3：普通账单(正常收房租务计划) 4：续约结算产生的"-->
            <template slot-scope="scope">
              <span v-if="scope.row.billType==1">收房贷变更</span>
              <span v-if="scope.row.billType==2">退租变更</span>
              <span v-if="scope.row.billType==3">普通账单</span>
              <span v-if="scope.row.billType==4">续约结算</span>
            </template>
          </el-table-column>
          <el-table-column label="预定付款日期" align="center" prop="payableDate" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.payableDate, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="实际付款日期" align="center" prop="paidTime" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.paidTime, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="支付方式" align="center" prop="payMethod" >
            <!--      1:快捷同，2：支付宝，3：微信，4：现金，5：银行卡转账，6：POS机刷卡，99：其它-->
            <template slot-scope="scope">
              <span v-if="scope.row.payMethod==1">快捷同</span>
              <span v-if="scope.row.payMethod==2">支付宝</span>
              <span v-if="scope.row.payMethod==3">微信</span>
              <span v-if="scope.row.payMethod==4">现金</span>
              <span v-if="scope.row.payMethod==5">银行卡转账</span>
              <span v-if="scope.row.payMethod==6">POS机刷卡</span>
              <span v-if="scope.row.payMethod==99">其它</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                v-if="scope.row.payMethod==undefined"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['property:plan:edit']"
              >付款</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="金融服务付款单">
        <el-table v-loading="loading" :data="planList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column label="收房合同编号" align="center" prop="sfContractNo" />
          <el-table-column label="房产信息" align="center" prop="houseName" />
          <el-table-column label="业主姓名" align="center" prop="ownerName" />
          <el-table-column label="支付金额" align="center" prop="paymentAmount" />
          <el-table-column label="账期" align="center" prop="payNumber" >
            <template slot-scope="scope">
              <span>第{{scope.row.payNumber}}期</span>
            </template>
          </el-table-column>
          <el-table-column label="付款状态" align="center" prop="payState" >
            <!--        ,1、未付款；2、已付款 3、已中止4、 4：已冻结-->
            <template slot-scope="scope">
              <span v-if="scope.row.payState==1">未付款</span>
              <span v-if="scope.row.payState==2">已付款</span>
              <span v-if="scope.row.payState==3">已中止</span>
              <span v-if="scope.row.payState==4">已冻结</span>
            </template>
          </el-table-column>
          <el-table-column label="账单类型" align="center" prop="billType" >
            <!--          1：收房贷变更2：退租变更    3：普通账单(正常收房租务计划) 4：续约结算产生的"-->
            <template slot-scope="scope">
              <span v-if="scope.row.billType==1">收房贷变更</span>
              <span v-if="scope.row.billType==2">退租变更</span>
              <span v-if="scope.row.billType==3">普通账单</span>
              <span v-if="scope.row.billType==4">续约结算</span>
            </template>
          </el-table-column>
          <el-table-column label="预定付款日期" align="center" prop="payableDate" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.payableDate, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="实际付款日期" align="center" prop="paidTime" width="180">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.paidTime, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>
          <el-table-column label="支付方式" align="center" prop="payMethod" >
            <!--      1:快捷同，2：支付宝，3：微信，4：现金，5：银行卡转账，6：POS机刷卡，99：其它-->
            <template slot-scope="scope">
              <span v-if="scope.row.payMethod==1">快捷同</span>
              <span v-if="scope.row.payMethod==2">支付宝</span>
              <span v-if="scope.row.payMethod==3">微信</span>
              <span v-if="scope.row.payMethod==4">现金</span>
              <span v-if="scope.row.payMethod==5">银行卡转账</span>
              <span v-if="scope.row.payMethod==6">POS机刷卡</span>
              <span v-if="scope.row.payMethod==99">其它</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                v-if="scope.row.payMethod==undefined"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['property:plan:edit']"
              >付款</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>
    </el-tabs>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <el-dialog title="付款详情" :visible.sync="dialogFormVisible">
      <el-form :model="formByFu">
        <el-form-item label="付款金额" :label-width="formLabelWidth">
          <span>{{formByFu.paymentAmount}}</span>
        </el-form-item>
        <el-form-item label="付款方式" :label-width="formLabelWidth">
          <el-select v-model="formByFu.payMethod" placeholder="请选择付款方式">
            <!--      1:快捷同，2：支付宝，3：微信，4：现金，5：银行卡转账，6：POS机刷卡，99：其它-->
            <el-option label="快捷同" value="1"></el-option>
            <el-option label="支付宝" value="2"></el-option>
            <el-option label="微信" value="3"></el-option>
            <el-option label="现金" value="4"></el-option>
            <el-option label="银行卡转账" value="5"></el-option>
            <el-option label="POS机刷卡" value="6"></el-option>
            <el-option label="其它" value="99"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="fukuan(formByFu)">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listPlan, getPlan, delPlan, addPlan, updatePlan } from "@/api/property/plan";

export default {
  name: "Plan",
  data() {
    return {
      formLabelWidth: '120px',
      dialogFormVisible: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 付款计划管理表格数据
      planList: [],
      // 弹出层标题
      title: "",
      //账单类型
      billTypes:[
        //:1：分期变更2：租约保理变更3：退租变更4：普通账单
        {value: 1, label: '分期变更'},
        {value: 2, label: '租约保理变更'},
        {value: 3, label: '退租变更'},
        {value: 4, label: '普通账单'},
      ],
      //付款状态
      payStates: [
        {value: 1, label: '处理中'}
        ,{value: 2, label: '成功'}
        ,{value: 3, label: '失败'},
      ],
      // 查询参数
      queryParams: {
        itemFlag:1,
        pageNum: 1,
        pageSize: 10,
        payOrderNo: null,
        businessId: null,
        contractId: null,
        contractNo: null,
        contractType: null,
        tTerminationId: null,
        premiseId: null,
        premiseName: null,
        ownerId: null,
        ownerName: null,
        tenantId: null,
        tenantName: null,
        payType: null,
        payState: null,
        billType: null,
        itemType: null,
        otherItemName: null,
        paymentAmount: null,
        realPaymentAmount: null,
        withPayPlanId: null,
        paymentDaysBegin: null,
        paymentDaysEnd: null,
        payableDate: null,
        paidTime: null,
        payNumber: null,
        payMethod: null,
        otherPayMethod: null,
        payFlowNo: null,
        rentalPrice: null,
        tax: null,
        operationUser: null,
        totalPayNumber: null,
        repayType: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        delFlg: null,
        createUserid: null,
        updateUserid: null,
      },
      // 表单参数
      form: {},
      formByFu:{},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /**tabs点击事件*/
    tabs(tab, event){
      if(tab.index==0){
        this.queryParams.itemFlag=1
      }else if(tab.index==1){
        this.queryParams.itemFlag=2
      }else if(tab.index==2){
        this.queryParams.itemFlag=3
      }
      console.log(this.queryParams)
      this.getList();
    },
    /** 查询付款计划管理列表 */
    getList() {
      this.loading = true;
      listPlan(this.queryParams).then(response => {
        console.log(response.rows)
        this.planList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        payOrderNo: null,
        businessId: null,
        contractId: null,
        contractNo: null,
        contractType: null,
        tTerminationId: null,
        premiseId: null,
        premiseName: null,
        ownerId: null,
        ownerName: null,
        tenantId: null,
        tenantName: null,
        payType: null,
        payState: null,
        billType: null,
        itemType: null,
        otherItemName: null,
        paymentAmount: null,
        realPaymentAmount: null,
        withPayPlanId: null,
        paymentDaysBegin: null,
        paymentDaysEnd: null,
        payableDate: null,
        paidTime: null,
        payNumber: null,
        payMethod: null,
        otherPayMethod: null,
        payFlowNo: null,
        rentalPrice: null,
        tax: null,
        operationUser: null,
        totalPayNumber: null,
        repayType: null,
        remark: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        delFlg: null,
        createUserid: null,
        createTime: null,
        updateUserid: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
 /*   /!** 新增按钮操作 *!/
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加付款计划管理";
    },*/
    /**打开付款对话框*/
    handleUpdate(row){
      this.dialogFormVisible=true;

      this.formByFu=row;
    },
    /** 付款按钮操作 */
    fukuan(row) {
      if(row.payMethod==2){
          window.open("http://localhost:9402/plan/cz?price="+row.paymentAmount+"&id="+row.paymentId);
      }else{
        console.log("后台的值：：：：：：：：")
        console.log(row)
        updatePlan(row).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "付款";
        });
      }
      this.dialogFormVisible=false;
      this.getList();

      // this.reset();
      //

    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('property/plan/export', {
        ...this.queryParams
      }, `plan_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
